﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.PersistenceObject.History;
using WMS.FC.Domain.Repository;
using WMS.FC.Domain.Service.System.Interface;

namespace WMS.FC.Domain.Service.System
{
    public class InitializeSplitTableService : ServiceBase, IInitializeSplitTableService
    {
        protected readonly ISplitTableRepository splitTableRepository;

        public InitializeSplitTableService(
            ILogger<ServiceBase> logger,
            IOptions<WmsSettings> options,
            IMapper mapper,
            ISplitTableRepository splitTableRepository)
            : base(logger, options, mapper)
        {
            this.splitTableRepository = splitTableRepository;
        }

        public async Task<ActionResultBase> InitializeSplitTable()
        {
            var result = new ActionResultBase("初始化分表");
            try
            {
                await splitTableRepository.InitializeTable<HisCellBindPO>();
                await splitTableRepository.InitializeTable<HisCellNgPO>();
                await splitTableRepository.InitializeTable<HisCellOfflinePO>();
                await splitTableRepository.InitializeTable<HisCellProcessPO>();
                await splitTableRepository.InitializeTable<HisOperationPO>();
                await splitTableRepository.InitializeTable<HisResultDataPO>();
                await splitTableRepository.InitializeTable<HisTaskPO>();
            }
            catch (Exception ex)
            {
                return result.Exception(ex);
            }

            return result;
        }
    }
}
